package com.xaiojimao.gr_common.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.xaiojimao.gr_common.CommonEnum.BizCommonEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@AllArgsConstructor
@NoArgsConstructor
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result implements Serializable {
    private Object data;
    private String msg;
    private Integer code;

    public static Result success() {
        return new Result(null, "成功", 200);
    }

    public static Result success(Object data) {
        return new Result(data, "成功", 200);
    }

    public static Result fail() {
        return new Result(null, "操作失败", 502);
    }

    public static Result fail(BizCommonEnum commonEnum) {
        return new Result(null, commonEnum.getMsg(), commonEnum.getCode());
    }

    public static Result fail(Integer code, String msg) {
        return new Result(null, msg, code);
    }
}
